import httpInstance from "@/utils/http.js";
import {useUserStore} from "@/stores/user.js";


//更新个人信息
export function updateUserInfoAPI(userInfo){
    return httpInstance({
        url:'/user/baseInfo/update',
        method:'post',
        data: userInfo,
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    }).catch( function (error){
        console.error('更新个人信息失败:', error);
    })
}

//修改密码
export function updatePasswordAPI(uid,password){
    return httpInstance({
        url:`/user/NewPassword`,
        method:'put',
        params:{
            uid:uid,
            password:password
        }
    })
}

//获取个人信息
export function getUserInfoAPI(uid){
    return httpInstance({
        url:`/user/${uid}`,
        method:'get',
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    })
}

//上传头像
export function uploadAvatarAPI(formData){
    return httpInstance({
        url:'/user/avatar/update',
        method:'post',
        data: formData,
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    }).catch( function (error){
        console.error('上传出错:', error);
    })
}

//获取用户头像
export function getAvatarAPI(){
    return httpInstance({
        url:'/user/login',
        method:'post',
        data:{
            uid:useUserStore().userInfo.uid,
            password:useUserStore().userInfo.password
        },
    }).catch( function (error){
        console.error('头像获取失败', error);
    })
}

//注册店铺
export function registerShopAPI(shopInfo){
    return httpInstance({
        url:'/user/openShop',
        method:'post',
        data:shopInfo,
        headers: {
            'Content-Type': 'multipart/form-data',
        }
    })
}

//uid查询店铺
export function getUserShopAPI(uid){
    return httpInstance({
        url:`/user/shopByUid/${uid}`,
        method:'get',
    })
}

//shopId查询店铺
export function getShopByShopIdAPI(shopId){
    return httpInstance({
        url:`/user/shopByShopId/${shopId}`,
        method:'get',
    })
}


//查询专家信息
export function getExpertInfoAPI(uid){
    return httpInstance({
        url:`/expert/expertInfo/${uid}`,
        method:'get',
    })
}